<?php 

function option($items, $parent_id, $cat_id, $level=0) {
    foreach ($items as $item) {
        if ($item['id']==$cat_id) continue;
        
        $selected = ($item['id']==$parent_id) ? 'selected' : '';
        echo '<option value="'.$item['id'].'" '.$selected.'>';
        echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level).$item['name'];
        if (isset($item['children']) && is_array($item['children'])) {
            option($item['children'], $parent_id, $cat_id, $level+1);
        }
        echo '</option>';
    }
}
?>

<h3 class="page-header">添加项目成员  &nbsp; &nbsp;<span id="add">+</span> &nbsp; &nbsp; <span id="del">-</span></h3>
<form action="<?php URL::curr()?>"  method="post" class="form-horizontal">
	<div class="row">
    	<div class="col-sm-3">
    	
        	<div class="form-group">
        		<label class="col-sm-4 control-label">成员类型</label>
        		<div class="col-sm-8">
            		<select class="form-control" name="user_id[]">
            		<option value="0"> -选择成员类型- </option>
            		<?php if(Arr::get($_GET, 'pid')):?>
        			<?php option($cat_tree, Arr::get($_GET, 'pid'), 0);?>
        			<?php else:?>
        			<?php option($cat_tree, $info['user_id'], $info['id']);?>
        			<?php endif;?>		
                    </select>
                </div>
        	</div>
        	
        	<div class="form-group">
        		<label class="col-sm-4 control-label">成员</label>
        		<div class="col-sm-8">
            		<select class="form-control" name="person_cate_id[]">
            		<option value="0"> -选择成员- </option>
            		<?php foreach ($personInfo as $item):?>
            		<option value="<?= $item['id'] ?>"> <?= $item['nick_name'] ?> </option>
            		<?php endforeach;?>
                    </select>
                </div>
        	</div>
        	
        	<div class="form-group">
        		<label class="col-sm-4 control-label">项目报酬</label>
        		<div class="col-sm-8">
        			<input class="form-control" type="text" name="remuneration[]" value="<?= $info['remuneration'] ?>" required >
        		</div>
        	</div>
        	
        	<div class="form-group">
        		<label class="col-sm-4 control-label">结算报酬</label>
        		<div class="col-sm-8">
        			<input class="form-control" type="text" name="real_remuneration[]" value="<?= $info['real_remuneration'] ?>" required >
        		</div>
        	</div>
        	
        	
        	
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-offset-1 col-sm-3">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
	</div>		
</form>
<?= HTML::script('static/tinymce/tinymce.min.js')?>

<script>
	var  str=`<div class="col-sm-3">
	<div class="form-group">
		<label class="col-sm-4 control-label">人才类型</label>
		<div class="col-sm-8">
    		<select class="form-control" name="user_id[]">
    		<option value="0"> -选择人才类型- </option>	
    		<?php if(Arr::get($_GET, 'pid')):?>
			<?php option($cat_tree, Arr::get($_GET, 'pid'), 0);?>
			<?php else:?>
			<?php option($cat_tree, $info['user_id'], $info['id']);?>
			<?php endif;?>
            </select>
        </div>
	</div>
	<div class="form-group">
		<label class="col-sm-4 control-label">人才</label>
		<div class="col-sm-8">
    		<select class="form-control" name="person_cate_id[]">
    		<option value="0"> -选择人才- </option>
    		<?php foreach ($personInfo as $item):?>
    		<option value="<?= $item['id'] ?>"> <?= $item['nick_name'] ?> </option>
    		<?php endforeach;?>
            </select>
        </div>
	</div>

	<div class="form-group">
    	<label class="col-sm-4 control-label">项目报酬</label>
    	<div class="col-sm-8">
    		<input class="form-control" type="text" name="remuneration[]" value="<?= $info['remuneration'] ?>" required >
    	</div>
    </div>

    <div class="form-group">
    	<label class="col-sm-4 control-label">结算报酬</label>
    	<div class="col-sm-8">
    		<input class="form-control" type="text" name="real_remuneration[]" value="<?= $info['real_remuneration'] ?>" required >
    	</div>
    </div>
	</div>`
	$("#add").click(function(){
		$(".row").append(str)
	})
	$("#del").click(function(){
		if($(".row .col-sm-3").length>1){
			$(".row .col-sm-3:nth-last-child(1)").remove();
		}
	})
	
</script>